package com.healthbox.appointmentservice.DTO;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.healthbox.appointmentservice.entity.AppointmentLimit;
import com.healthbox.appointmentservice.entity.Hospital;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalTime;

/**
 * @author pengpeng
 * @date 2022/5/12
 */
@Data
@ApiModel(value = "检测时间段", description = "机构设置的检测时间段，即预约时可选择的目标,机构每次发布的预约日期限制会插入一条记录而不是在一条记录中修改，这样可以保留发布历史")
public class AppointmentLimitDTO {
    @ApiModelProperty(value = "预约限制对应日期", example = "2022-05-20")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    private LocalDate date;
    @ApiModelProperty(value = "当前预约可检测时间段开始时间", example = "08:30:00")
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    private LocalTime startTime;
    @ApiModelProperty(value = "当前预约可检测时间段结束时间", example = "17:05:00")
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
    private LocalTime endTime;
    @ApiModelProperty(value = "当前检测时间段可预约总人数", example = "100")
    private Integer maxNumber;
    @ApiModelProperty(value = "该检测限制所属机构对应编号", example = "1")
    private Long hospitalId;

    public static AppointmentLimit toEntity(AppointmentLimitDTO dto, Hospital hospital){
        assert (dto.getHospitalId().equals(hospital.getHospitalId()));
        return AppointmentLimit.builder()
                .date(dto.getDate())
                .startTime(dto.getStartTime())
                .endTime((dto.getEndTime()))
                .maxNumber((dto.getMaxNumber()))
                .hospital(hospital)
                .build();
    }
}
